home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-10-06 | 24.1 KB | 1,322 lines | [TEXT/CWIE] |
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLE
- // a fast Run-Length-Encoding masked software blitter.
- //
- // based on original code by Mick Foley <mick@emf.net>
- // from the book "Tricks of the Mac Game Programming Gurus" by Hayden Books.
- //
- // Written by Anders F Björklund <afb@algonet.se>, Nov. 1999
- // © 1998-99 afb. All rights reserved.
- ///--------------------------------------------------------------------------------------
-
- #ifndef __BLITPIXIE__
- #include "BlitPixieHeader.h"
- #endif
-
- #include "BlitPixieAsm.h"
-
- #define ALIGN_PTR(p) ( -((long) p) & 3)
-
- #pragma mark *** PowerPC asm:
- #if USE_PPC_ASSEMBLY
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLE - no clipping performed
- ///--------------------------------------------------------------------------------------
-
- ASM_FUNC void BlitPixieRLE(
- register unsigned char *srcTokens, // r3
- register unsigned char *dstPixelPTemp, // r4
- register unsigned long dstRowBytes) // r5
- {
- #define r_token r31
- #define r_op r30
- #define r_count r31 // recycled
- #define r_blocks r29
- #define r_dstRow r28
- #define r_dstBytes r27
- #define r_align r26
-
- ASM_BEGIN
- stmw r26,-24(SP)
-
- mr r_dstRow,r4
- mr r_dstBytes,r5
-
- @tokenloop:
- lwz r_token,0(r3)
- addi r3,r3,4
- rlwinm r_op,r_token,32-kTokenShift,kTokenShift,31
- rlwinm r_count,r_token,0,32-kTokenShift,31
-
- cmplwi r_op,kDrawPixelsToken
- // STALL!
- bne @notdraw
- //================================================== Draw Token
-
- rlwinm r0,r4,0,30,31
- rlwinm r_blocks,r_count,27,5,31 // blocks = bytes / 32
- rlwinm r_count,r_count,0,27,31 // bytes %= 32
-
- cmplwi cr5,r0,0
- cmplwi cr6,r_blocks,0
- cmplwi cr7,r_count,0
-
- mtctr r_blocks
- mtxer r_count
-
- beq cr6,@skipblocks
- bne cr5,@unaligned
-
- @aligned:
- @doubleloop:
- lfd fp1,0(r3)
- lfd fp2,8(r3)
- lfd fp3,16(r3)
- lfd fp4,24(r3)
- addi r3,r3,32
- stfd fp1,0(r4)
- stfd fp2,8(r4)
- stfd fp3,16(r4)
- stfd fp4,24(r4)
- addi r4,r4,32
- bdnz @doubleloop
- b @skipblocks
-
- @unaligned:
- @blockloop:
- lwz r5,0(r3)
- lwz r6,4(r3)
- lwz r7,8(r3)
- lwz r8,12(r3)
- lwz r9,16(r3)
- lwz r10,20(r3)
- lwz r11,24(r3)
- lwz r12,28(r3)
- addi r3,r3,32
- stw r5,0(r4)
- stw r6,4(r4)
- stw r7,8(r4)
- stw r8,12(r4)
- stw r9,16(r4)
- stw r10,20(r4)
- stw r11,24(r4)
- stw r12,28(r4)
- addi r4,r4,32
- bdnz @blockloop
- @skipblocks:
-
- beq cr7,@skipbytes
- lswx r5,r0,r3
- add r3,r3,r_count
- stswx r5,r0,r4
- add r4,r4,r_count
- @skipbytes:
-
- addi r3,r3,3
- rlwinm r3,r3,0,0,29
-
- b @tokenloop
-
- @notdraw:
- cmplwi r_op,kSkipPixelsToken
- // STALL!
- bne @notskip
- //================================================== Skip Token
- add r4,r4,r_count
- b @tokenloop
-
- @notskip:
- cmplwi r_op,kSingleColorToken
- // STALL!
- bne @notfill
- //================================================== Fill Token
-
- lwz r5,0(r3)
- addi r3,r3,4
-
- rlwinm r0,r4,0,30,31
- rlwinm r_blocks,r_count,27,5,31 // blocks = bytes / 32
- rlwinm r_count,r_count,0,27,31 // bytes %= 32
-
- cmplwi cr5,r0,0
- cmplwi cr6,r_blocks,0
- cmplwi cr7,r_count,0
-
- mtctr r_blocks
- mtxer r_count
-
- beq cr6,@skipblocks2
- bne cr5,@unaligned2
- @aligned2:
-
- stw r5,-32(SP)
- stw r5,-28(SP)
- lfd fp0,-32(SP)
-
- @doubleloop2:
- stfd fp0,0(r4)
- stfd fp0,8(r4)
- stfd fp0,16(r4)
- stfd fp0,24(r4)
- addi r4,r4,32
- bdnz @doubleloop2
- b @skipblocks2
-
- @unaligned2:
- @blockloop2:
- stw r5,0(r4)
- stw r5,4(r4)
- stw r5,8(r4)
- stw r5,12(r4)
- stw r5,16(r4)
- stw r5,20(r4)
- stw r5,24(r4)
- stw r5,28(r4)
- addi r4,r4,32
- bdnz @blockloop2
- @skipblocks2:
-
- beq cr7,@skipbytes2
- mr r6,r5
- mr r7,r5
- mr r8,r5
- mr r9,r5
- mr r10,r5
- mr r11,r5
- mr r12,r5
- stswx r5,r0,r4
- add r4,r4,r_count
- @skipbytes2:
-
- b @tokenloop
-
- @notfill:
- cmplwi r_op,kLineStartToken
- // STALL!
- bne @notstart
- //================================================== Line Start Token
- mr r4,r_dstRow
- add r_dstRow,r_dstRow,r_dstBytes
- b @tokenloop
-
- @notstart:
- cmplwi r_op,kEndShapeToken
- beq @end
-
- @notend:
- // bl Debugger // <-- unknown token encountered
- // nop
-
- //================================================== End Shape Token
- @end:
- lmw r26,-24(SP)
- ASM_END
- }
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLEClipped
- ///--------------------------------------------------------------------------------------
-
- ASM_FUNC void BlitPixieRLEClipped(
- register unsigned char *srcTokens, // r3
- register unsigned char *dstPixelPTemp, // r4
- register unsigned long dstRowBytes, // r5
- register Rect *dstClipRect) // r6
- {
- #define r_token r31
- #define r_op r30
- #define r_count r31 // recycled
- #define r_blocks r29
- #define r_dstRow r28
- #define r_dstBytes r27
- #define r_spanend r26
- #define r_extra r25
- #define r_inc r24
- #define r_clipLeft r23
- #define r_clipRight r22
- #define r_clipTop r21
- #define r_clipBottom r20
- #define r_x r19
- #define r_y r18
-
- ASM_BEGIN
- stmw r18,-60(SP)
-
- lha r_clipTop,0(r6)
- lha r_clipLeft,2(r6)
- lha r_clipBottom,4(r6)
- lha r_clipRight,6(r6)
-
- mr r_dstRow,r4
- mr r_dstBytes,r5
- li r_y,0
-
- @tokenloop:
- lwz r_token,0(r3)
- addi r3,r3,4
- rlwinm r_op,r_token,32-kTokenShift,kTokenShift,31
- rlwinm r_count,r_token,0,32-kTokenShift,31
-
- cmplwi r_op,kDrawPixelsToken
- bne @notdraw
- //================================================== Draw Token
-
- // CHECK LEFT BORDER
- add r_spanend,r_x,r_count
- subi r_spanend,r_spanend,1
-
- cmplw cr5,r_x,r_clipLeft
- cmplw cr6,r_spanend,r_clipLeft
- bge cr5,@noleftclip
- ble cr6,@skiprun
-
- @leftclip: // clip left
- sub r_extra,r_clipLeft,r_x
- add r3,r3,r_extra
- add r4,r4,r_extra
- add r_x,r_x,r_extra
- sub r_count,r_count,r_extra
- @noleftclip:
-
- // CHECK RIGHT BORDER
- li r_extra,0
-
- cmplw cr5,r_spanend,r_clipRight
- cmplw cr6,r_x,r_clipRight
- blt cr5,@norightclip
- bge cr6,@skiprun
-
- @rightclip: // clip right
- sub r_extra,r_spanend,r_clipRight
- sub r_count,r_count,r_extra
- @norightclip:
-
- // DRAW SPAN
- rlwinm r_blocks,r_count,27,5,31 // blocks = bytes >> 5
- rlwinm r_count,r_count,0,27,31 // bytes &= 31
-
- cmplwi cr6,r_blocks,0
- cmplwi cr7,r_count,0
-
- mtxer r_count
- add r_count,r_count,r_extra // adjust for right clipping
-
- beq cr6,@skipblocks
- mtctr r_blocks
- @blockloop:
- addi r_x,r_x,32
- lwz r5, 0(r3)
- lwz r6, 4(r3)
- lwz r7, 8(r3)
- lwz r8,12(r3)
- lwz r9,16(r3)
- lwz r10,20(r3)
- lwz r11,24(r3)
- lwz r12,28(r3)
- addi r3,r3,32
- stw r5, 0(r4)
- stw r6, 4(r4)
- stw r7, 8(r4)
- stw r8,12(r4)
- stw r9,16(r4)
- stw r10,20(r4)
- stw r11,24(r4)
- stw r12,28(r4)
- addi r4,r4,32
- bdnz @blockloop
- @skipblocks:
-
- beq cr7,@skiprun
- lswx r5,r0,r3
- stswx r5,r0,r4
- @skiprun:
-
- add r3,r3,r_count
- add r4,r4,r_count
- add r_x,r_x,r_count
-
- addi r3,r3,3
- rlwinm r3,r3,0,0,29
-
- b @tokenloop
-
- @notdraw:
- cmplwi r_op,kSkipPixelsToken
- bne @notskip
- //================================================== Skip Token
- add r4,r4,r_count
- add r_x,r_x,r_count
- b @tokenloop
-
- @notskip:
- cmplwi r_op,kSingleColorToken
- bne @notfill
- //================================================== Fill Token
-
- // CHECK LEFT BORDER
- add r_spanend,r_x,r_count
- subi r_spanend,r_spanend,1
-
- cmplw cr5,r_x,r_clipLeft
- cmplw cr6,r_spanend,r_clipLeft
- bge cr5,@noleftclip2
- ble cr6,@skiprun2
-
- @leftclip2: // clip left
- sub r_extra,r_clipLeft,r_x
- add r4,r4,r_extra
- add r_x,r_x,r_extra
- sub r_count,r_count,r_extra
- @noleftclip2:
-
- // CHECK RIGHT BORDER
- li r_extra,0
-
- cmplw cr5,r_spanend,r_clipRight
- cmplw cr6,r_x,r_clipRight
- blt cr5,@norightclip2
- bge cr6,@skiprun2
-
- @rightclip2: // clip right
- sub r_extra,r_spanend,r_clipRight
- sub r_count,r_count,r_extra
- @norightclip2:
-
- // DRAW SPAN
- rlwinm r_blocks,r_count,27,5,31 // blocks = bytes >> 5
- rlwinm r_count,r_count,0,27,31 // bytes &= 31
-
- lwz r5,0(r3)
-
- cmplwi cr6,r_blocks,0
- cmplwi cr7,r_count,0
-
- mtxer r_count
- add r_count,r_count,r_extra // adjust for right clipping
-
- beq cr6,@skipblocks2
- mtctr r_blocks
- @blockloop2:
- addi r_x,r_x,32
- stw r5,0(r4)
- stw r5,4(r4)
- stw r5,8(r4)
- stw r5,12(r4)
- stw r5,16(r4)
- stw r5,20(r4)
- stw r5,24(r4)
- stw r5,28(r4)
- addi r4,r4,32
- bdnz @blockloop2
- @skipblocks2:
-
- beq cr7,@skiprun2
- mr r6,r5
- mr r7,r5
- mr r8,r5
- mr r9,r5
- mr r10,r5
- mr r11,r5
- mr r12,r5
- stswx r5,r0,r4
- @skiprun2:
-
- addi r3,r3,4
- add r4,r4,r_count
- add r_x,r_x,r_count
-
- b @tokenloop
-
- @notfill:
- cmplwi r_op,kLineStartToken
- bne @notstart
- //================================================== Line Start Token
- cmplw r_y,r_clipTop
- bge @notabove
- add r3,r3,r_count // skip if above clip
- @notabove:
-
- cmplw r_y,r_clipBottom
- bge @end // end if below clip
-
- mr r4,r_dstRow
- add r_dstRow,r_dstRow,r_dstBytes
- li r_x,0
- addi r_y,r_y,1
-
- b @tokenloop
-
- @notstart:
- cmplwi r_op,kEndShapeToken
- beq @end
-
- @notend:
- // bl Debugger // <-- unknown token encountered
- // nop
-
- @end:
- //================================================== End Shape Token
-
- lmw r18,-60(SP)
- ASM_END
- }
-
- #pragma mark *** 680X0 asm:
- #elif USE_68K_ASSEMBLY
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLE - no clipping performed
- ///--------------------------------------------------------------------------------------
-
- ASM_FUNC void BlitPixieRLE(
- unsigned char *srcTokens,
- unsigned char *dstPixel,
- unsigned long dstRowBytes)
- {
- ASM_BEGIN
-
- MOVE.L A2,-(SP)
-
- MOVEA.L srcTokens,A0
- MOVEA.L dstPixel,A1
- MOVEA.L A1,A2
- MOVE.L dstRowBytes,D2
-
- CLR.L D1
-
- @tokenloop:
- MOVE.L (A0)+,D0
- MOVE.L D0,D1
-
- ROL.L #32 - kTokenShift,D0
- ANDI.L #kCountMask,D1
-
- CMPI.B #kDrawPixelsToken,D0
- BNE @notdraw
-
- //================================================== Draw Pixels
-
- MOVE.W D1,D0
- LSR.W #4,D0
- BEQ.S @noloops
-
- SUBQ.W #1,D0
- @loop:
- MOVE.L (A0)+,(A1)+
- MOVE.L (A0)+,(A1)+
- MOVE.L (A0)+,(A1)+
- MOVE.L (A0)+,(A1)+
-
- DBRA D0,@loop
- @noloops:
-
- MOVE.W D1,D0
- ANDI.W #8,D0
- BEQ.S @not8
- MOVE.L (A0)+,(A1)+
- MOVE.L (A0)+,(A1)+
- @not8:
-
- MOVE.W D1,D0
- ANDI.W #4,D0
- BEQ.S @not4
- MOVE.L (A0)+,(A1)+
- @not4:
-
- MOVE.W D1,D0
- ANDI.W #2,D0
- BEQ.S @not2
- MOVE.W (A0)+,(A1)+
- @not2:
-
- MOVE.W D1,D0
- ANDI.W #1,D0
- BEQ.S @not1
- MOVE.B (A0)+,(A1)+
- @not1:
-
- MOVE.L A0,D0
- ADDQ.L #3,D0
- ANDI.W #~3,D0
- MOVEA.L D0,A0
-
- BRA @tokenloop
-
- @notdraw:
- CMPI.B #kSkipPixelsToken,D0
- BNE @notskip
- //================================================== Skip Pixels
-
- ADDA.L D1,A1
-
- BRA @tokenloop
-
- @notskip:
- CMPI.B #kSingleColorToken,D0
- BNE @notfill
- //================================================== Fill Pixels
-
- MOVE.W D1,D0
- LSR.W #4,D0
- BEQ @nofillloops
-
- SUBQ.W #1,D0
- @fillloop:
- MOVE.L (A0),(A1)+
- MOVE.L (A0),(A1)+
- MOVE.L (A0),(A1)+
- MOVE.L (A0),(A1)+
-
- DBRA D0,@fillloop
- @nofillloops:
-
- MOVE.W D1,D0
- ANDI.W #8,D0
- BEQ.S @notfill8
- MOVE.L (A0),(A1)+
- MOVE.L (A0),(A1)+
- @notfill8:
-
- MOVE.W D1,D0
- ANDI.W #4,D0
- BEQ.S @notfill4
- MOVE.L (A0),(A1)+
- @notfill4:
-
- MOVE.W D1,D0
- ANDI.W #2,D0
- BEQ.S @notfill2
- MOVE.W (A0),(A1)+
- @notfill2:
-
- MOVE.W D1,D0
- ANDI.W #1,D0
- BEQ.S @notfill1
- MOVE.B (A0),(A1)+
- @notfill1:
-
- ADDQ.L #4,A0
-
- BRA @tokenloop
-
- @notfill:
- CMPI.B #kLineStartToken,D0
- BNE @notline
- //================================================== Line Start
-
- MOVEA.L A2,A1
- ADDA.L D2,A2
-
- BRA @tokenloop
-
- @notline:
- CMPI.B #kEndShapeToken,D0
- BEQ @end
- //================================================== Shape Ends
-
- @notend:
- // _Debugger // <-- unknown token encountered
-
- @end:
- MOVE.L (SP)+,A2
-
- ASM_END
- }
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLEClipped
- ///--------------------------------------------------------------------------------------
-
- ASM_FUNC void BlitPixieRLEClipped(
- unsigned char *srcTokens,
- unsigned char *dstPixel,
- unsigned long dstRowBytes,
- Rect *dstClipRect)
- {
- #define D_x D3
- #define D_y D4
- #define D_blocks D5
- #define D_extra D6
-
- #define D_clipTop (A3)
- #define D_clipLeft 2(A3)
- #define D_clipBottom 4(A3)
- #define D_clipRight 6(A3)
-
- ASM_BEGIN
-
- MOVEM.L D3-D6/A2-A3,-(SP) // D0-D2,A0-A1 are volatile
-
- MOVEA.L srcTokens,A0
- MOVEA.L dstPixel,A1
- MOVEA.L A1,A2
- MOVE.L dstRowBytes,D2
- MOVEA.L dstClipRect,A3
-
- MOVEQ #0,D_y
- CLR.L D1
- CLR.L D_extra
-
- @tokenloop:
- MOVE.L (A0)+,D0
- MOVE.L D0,D1
- ROL.L #32 - kTokenShift,D0
- ANDI.L #kCountMask,D1
-
- CMPI.B #kDrawPixelsToken,D0
- BNE @notdraw
- //================================================== Draw Token
-
- MOVE.W D_x,D0
- ADD.W D1,D0
- SUBQ.W #1,D0
-
- CMP.W D_clipLeft,D_x
- BGE.S @noleftclip
- CMP.W D_clipLeft,D0
- BGT.S @leftclip
-
- @skipleft:
- // skip this run (totally outside)
- ADDA.L D1,A0
- ADDA.L D1,A1
- ADD.W D1,D_x
-
- BRA @skip
-
- @leftclip:
- // clip left (clipLeft - x)
- MOVE.W D_clipLeft,D_extra
- SUB.W D_x,D_extra
- SUB.W D_extra,D1
-
- ADDA.L D_extra,A0
- ADDA.L D_extra,A1
- ADD.W D_extra,D_x
-
- @noleftclip:
- MOVEQ #0,D_extra
-
- CMP.W D_clipRight,D0
- BLT.S @norightclip
-
- CMP.W D_clipRight,D_x
- BLT.S @rightclip
-
- @skipright:
- BRA @skipleft
-
- @rightclip:
-
- // clip right
- MOVE.W D0,D_extra
- SUB.W D_clipRight,D_extra
-
- SUB.W D_extra,D1
-
- @norightclip:
- MOVE.W D1,D0
- LSR.W #4,D0
- BEQ.S @noloops
-
- SUBQ.W #1,D0
- @loop:
- MOVE.L (A0)+,(A1)+
- MOVE.L (A0)+,(A1)+
- MOVE.L (A0)+,(A1)+
- MOVE.L (A0)+,(A1)+
-
- DBRA D0,@loop
- @noloops:
-
- MOVE.W D1,D0
- ANDI.W #8,D0
- BEQ.S @not8
- MOVE.L (A0)+,(A1)+
- MOVE.L (A0)+,(A1)+
- @not8:
-
- MOVE.W D1,D0
- ANDI.W #4,D0
- BEQ.S @not4
- MOVE.L (A0)+,(A1)+
- @not4:
-
- MOVE.W D1,D0
- ANDI.W #2,D0
- BEQ.S @not2
- MOVE.W (A0)+,(A1)+
- @not2:
-
- MOVE.W D1,D0
- ANDI.W #1,D0
- BEQ.S @not1
- MOVE.B (A0)+,(A1)+
- @not1:
-
- ADD.W D1,D_x
-
- // adjust for right clipping
- ADDA.L D_extra,A0
- ADDA.L D_extra,A1
- ADD.W D_extra,D_x
-
- @skip:
- MOVE.L A0,D0
- ADDQ.L #3,D0
- ANDI.W #~3,D0
- MOVEA.L D0,A0
-
- BRA @tokenloop
-
- @notdraw:
- CMPI.B #kSkipPixelsToken,D0
- BNE.S @notskip
- //================================================== Skip Pixels
-
- ADDA.L D1,A1
- ADD.W D1,D_x
-
- BRA @tokenloop
-
- @notskip:
- CMPI.B #kSingleColorToken,D0
- BNE @notfill
- //================================================== Fill Pixels
-
- MOVE.W D_x,D0
- ADD.W D1,D0
- SUBQ.W #1,D0
-
- CMP.W D_clipLeft,D_x
- BGE.S @noleftclipFill
- CMP.W D_clipLeft,D0
- BGT.S @leftclipFill
-
- @skipleftFill:
- // skip this run (totally outside)
- ADDA.L D1,A1
- ADD.W D1,D_x
-
- ADDQ.L #4,A0
-
- BRA @tokenloop
-
- @leftclipFill:
- // clip left (clipLeft - x)
- MOVE.W D_clipLeft,D_extra
- SUB.W D_x,D_extra
- SUB.W D_extra,D1
-
- ADDA.L D_extra,A1
- ADD.W D_extra,D_x
-
- @noleftclipFill:
- MOVEQ #0,D_extra
-
- CMP.W D_clipRight,D0
- BLT.S @norightclipFill
-
- CMP.W D_clipRight,D_x
- BLT.S @rightclipFill
-
- @skiprightFill:
- BRA @skipleftFill
-
- @rightclipFill:
-
- // clip right
- MOVE.W D0,D_extra
- SUB.W D_clipRight,D_extra
-
- SUB.W D_extra,D1
-
- @norightclipFill:
-
- MOVE.W D1,D0
- LSR.W #4,D0
- BEQ.S @noloopsFill
-
- SUBQ.W #1,D0
- @loopFill:
- MOVE.L (A0),(A1)+
- MOVE.L (A0),(A1)+
- MOVE.L (A0),(A1)+
- MOVE.L (A0),(A1)+
-
- DBRA D0,@loopFill
- @noloopsFill:
-
- MOVE.W D1,D0
- ANDI.W #8,D0
- BEQ.S @notFill8
- MOVE.L (A0),(A1)+
- MOVE.L (A0),(A1)+
- @notFill8:
-
- MOVE.W D1,D0
- ANDI.W #4,D0
- BEQ.S @notFill4
- MOVE.L (A0),(A1)+
- @notFill4:
-
- MOVE.W D1,D0
- ANDI.W #2,D0
- BEQ.S @notFill2
- MOVE.W (A0),(A1)+
- @notFill2:
-
- MOVE.W D1,D0
- ANDI.W #1,D0
- BEQ.S @notFill1
- MOVE.B (A0),(A1)+
- @notFill1:
-
- ADD.W D1,D_x
-
- // adjust for right clipping
- ADDA.L D_extra,A1
- ADD.W D_extra,D_x
-
- ADDQ.L #4,A0
-
- BRA @tokenloop
-
- @notfill:
- CMPI.B #kLineStartToken,D0
- BNE.S @notstart
- //================================================== Line Start
-
- CMP.W D_clipTop,D_y
- BGE.S @notabove
- ADDA.L D1,A0 // skip line if above clip
- @notabove:
- CMP.W D_clipBottom,D_y
- BGE @end // end if below clip
-
- MOVEQ #0,D_x
- ADDQ.W #1,D_y
-
- MOVEA.L A2,A1
- ADDA.L D2,A2
-
- BRA @tokenloop
-
- @notstart:
- CMPI.B #kEndShapeToken,D0
- BEQ @end
-
- @notend:
- // _Debugger // <-- unknown token encountered
-
- @end:
- //================================================== End Shape Token
-
- MOVEM.L (SP)+,D3-D6/A2-A3
- ASM_END
- }
-
- #pragma mark *** Generic C:
- #elif USE_GENERIC_C
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLE - no clipping performed
- ///--------------------------------------------------------------------------------------
-
- void BlitPixieRLE(
- unsigned char *srcTokens,
- unsigned char *dstPixel,
- unsigned long dstRowBytes)
- {
- unsigned long token,op,count;
- unsigned char *dstRow;
-
- dstRow = dstPixel;
-
- do
- {
- token = *((TokenDataType *) srcTokens);
- srcTokens += sizeof(TokenDataType);
-
- op = token >> kTokenShift;
- count = token & kCountMask;
-
- switch ( op )
- {
- case kDrawPixelsToken:
- BlitPixieMemCopy( dstPixel, srcTokens, count );
- srcTokens += count;
- srcTokens += ALIGN_PTR(srcTokens);
- dstPixel += count;
- break;
- case kSkipPixelsToken:
- dstPixel += count;
- break;
- case kSingleColorToken:
- BlitPixieMemSet( dstPixel, *((unsigned long *) srcTokens), count );
- srcTokens += sizeof(long);
- dstPixel += count;
- break;
- case kLineStartToken:
- dstPixel = dstRow;
- dstRow += dstRowBytes;
- break;
- case kEndShapeToken:
- break;
- default:
- BLITPIXIE_DEBUGGER("BlitPixieRLE : compiled data contains unknown token!");
- return;
- }
-
- } while ( op != kEndShapeToken );
-
- }
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLEClipped
- ///--------------------------------------------------------------------------------------
-
- void BlitPixieRLEClipped(
- unsigned char *srcTokens,
- unsigned char *dstPixel,
- unsigned long dstOffset,
- Rect *dstClipRect )
- {
- unsigned short token,op;
- long count,extra,spanend;
- unsigned char *dstRow;
- int x,y;
-
- y = 0;
- dstRow = dstPixel;
-
- do
- {
- token = *srcTokens++;
-
- op = token >> kTokenShift;
- count = token & kCountMask;
-
- switch ( op )
- {
- case kDrawPixelsToken:
-
- spanend = x + count - 1;
-
- if ( x < dstClipRect->right && spanend > dstClipRect->left )
- {
- // clip left
- if ( x < dstClipRect->left )
- {
- extra = dstClipRect->left - x;
-
- count -= extra;
-
- x += extra;
- dstPixel += extra;
- srcTokens += extra;
- }
-
- // clip right
- extra = 0;
- if ( spanend > dstClipRect->right )
- {
- extra = spanend - dstClipRect->right;
-
- count -= extra;
- }
-
- BlitPixieMemCopy( dstPixel, srcTokens, count );
-
- x += extra;
- dstPixel += extra;
- srcTokens += extra;
-
- }
-
- x += count;
- dstPixel += count;
- srcTokens += count;
- srcTokens += ALIGN_PTR(srcTokens);
-
- break;
-
- case kSkipPixelsToken:
- x += count;
- dstPixel += count;
- break;
-
- case kSingleColorToken:
-
- spanend = x + count -1;
-
- if ( x < dstClipRect->right && spanend > dstClipRect->left )
- {
- // clip left
- if ( x < dstClipRect->left )
- {
- extra = dstClipRect->left - x;
-
- count -= extra;
-
- x += extra;
- dstPixel += extra;
- }
-
- // clip right
- extra = 0;
- if ( spanend > dstClipRect->right )
- {
- extra = spanend - dstClipRect->right;
-
- count -= extra;
- }
-
- BlitPixieMemSet( dstPixel, *((unsigned long *) srcTokens), count );
-
- x += extra;
- dstPixel += extra;
-
- }
-
- x += count;
- dstPixel += count;
-
- srcTokens += sizeof(long);
- break;
- case kLineStartToken:
- if ( y < dstClipRect->top )
- {
- // clip top (skip entire row)
- srcTokens += count;
- }
- else if ( y >= dstClipRect->bottom )
- {
- // clip bottom (end draw)
- op = kEndShapeToken;
- break;
- }
-
- x = 0;
- y++;
- dstPixel = dstRow;
- dstRow += dstOffset;
- break;
- case kEndShapeToken:
- break;
- default:
- BLITPIXIE_DEBUGGER("BlitPixieRLE : compiled data contains unknown token!");
- return;
-
- }
- } while ( op != kEndShapeToken );
-
- }
-
- #endif
-
-
- #pragma mark -
-
- #ifndef GENERATINGASM // do not include for asm file generation
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLEColor - draws the RLE mask in a specific color
- ///--------------------------------------------------------------------------------------
-
- void BlitPixieRLEColor(
- unsigned char *srcTokens,
- unsigned long srcColor,
- unsigned char *dstPixel,
- unsigned long dstRowBytes)
- {
- unsigned long token,op,count;
- unsigned char *dstRow;
-
- dstRow = dstPixel;
-
- do
- {
- token = *((TokenDataType *) srcTokens);
- srcTokens += sizeof(TokenDataType);
-
- op = token >> kTokenShift;
- count = token & kCountMask;
-
- switch ( op )
- {
- case kDrawPixelsToken:
- BlitPixieMemSet( dstPixel, srcColor, count );
- dstPixel += count;
- srcTokens += count;
- srcTokens += ALIGN_PTR(srcTokens);
- break;
- case kSkipPixelsToken:
- dstPixel += count;
- break;
- case kSingleColorToken:
- BlitPixieMemSet( dstPixel, srcColor, count );
- dstPixel += count;
- srcTokens += sizeof(long);
- break;
- case kLineStartToken:
- dstPixel = dstRow;
- dstRow += dstRowBytes;
- break;
- case kEndShapeToken:
- break;
- default:
- BLITPIXIE_DEBUGGER("BlitPixieRLE : compiled data contains unknown token!");
- return;
- }
-
- } while ( op != kEndShapeToken );
-
- }
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLEColorClipped
- ///--------------------------------------------------------------------------------------
-
- void BlitPixieRLEColorClipped(
- unsigned char *srcTokens,
- unsigned long srcColor,
- unsigned char *dstPixel,
- unsigned long dstOffset,
- Rect *dstClipRect )
- {
- unsigned short token,op;
- long count,extra,spanend;
- unsigned char *dstRow;
- int x,y;
-
- y = 0;
- dstRow = dstPixel;
-
- do
- {
- token = *((TokenDataType *) srcTokens);
- srcTokens += sizeof(TokenDataType);
-
- op = token >> kTokenShift;
- count = token & kCountMask;
-
- switch ( op )
- {
- case kDrawPixelsToken:
-
- spanend = x + count - 1;
-
- if ( x < dstClipRect->right && spanend > dstClipRect->left )
- {
- // clip left
- if ( x < dstClipRect->left )
- {
- extra = dstClipRect->left - x;
-
- count -= extra;
-
- x += extra;
- dstPixel += extra;
- srcTokens += extra;
- }
-
- // clip right
- extra = 0;
- if ( spanend > dstClipRect->right )
- {
- extra = spanend - dstClipRect->right;
-
- count -= extra;
- }
-
- BlitPixieMemSet( dstPixel, srcColor, count );
-
- x += extra;
- dstPixel += extra;
- srcTokens += extra;
-
- }
-
- x += count;
- dstPixel += count;
- srcTokens += count;
- srcTokens += ALIGN_PTR(srcTokens);
-
- break;
-
- case kSkipPixelsToken:
- x += count;
- dstPixel += count;
- break;
-
- case kSingleColorToken:
-
- spanend = x + count -1;
-
- if ( x < dstClipRect->right && spanend > dstClipRect->left )
- {
- // clip left
- if ( x < dstClipRect->left )
- {
- extra = dstClipRect->left - x;
-
- count -= extra;
-
- x += extra;
- dstPixel += extra;
- }
-
- // clip right
- extra = 0;
- if ( spanend > dstClipRect->right )
- {
- extra = spanend - dstClipRect->right;
-
- count -= extra;
- }
-
- BlitPixieMemSet( dstPixel, srcColor, count );
-
- x += extra;
- dstPixel += extra;
-
- }
-
- x += count;
- dstPixel += count;
-
- srcTokens += sizeof(long);
- break;
- case kLineStartToken:
- if ( y < dstClipRect->top )
- {
- // clip top (skip entire row)
- srcTokens += count;
- }
- else if ( y >= dstClipRect->bottom )
- {
- // clip bottom (end draw)
- op = kEndShapeToken;
- break;
- }
-
- x = 0;
- y++;
- dstPixel = dstRow;
- dstRow += dstOffset;
- break;
- case kEndShapeToken:
- break;
- default:
- BLITPIXIE_DEBUGGER("BlitPixieRLE : compiled data contains unknown token!");
- return;
-
- }
- } while ( op != kEndShapeToken );
-
- }
-
- #endif GENERATINGASM
-